package com.gz.springboot;

import com.gz.springboot.bean.Cat;
import com.gz.springboot.bean.Dog;
import com.gz.springboot.bean.Monster;
import com.gz.springboot.config.BeanConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * SpringBootApplication 表示这是一个springboot的应用/项目
 * scanBasePackages = "com.gz" 指定springboot要扫描的包(可指定多个)，
 * 默认是主程序(main方法)所在的包及其子包会被扫描
 */
//@SpringBootApplication(scanBasePackages = "com.gz")
@SpringBootApplication
public class MainApp {
    public static void main(String[] args) {

        //启动springboot应用程序/项目
        ConfigurableApplicationContext ioc =
                SpringApplication.run(MainApp.class, args);

        Monster monster01=ioc.getBean("monster01", Monster.class);
        Monster monster02=ioc.getBean("monster01", Monster.class);
        System.out.println(monster01.hashCode());
        System.out.println(monster02.hashCode()); //Scope=singleton 是单例

        BeanConfig beanConfig = ioc.getBean(BeanConfig.class);
        Monster monster03 = beanConfig.monster01();
        Monster monster04 = beanConfig.monster01();
        System.out.println(monster03.hashCode());
        System.out.println(monster04.hashCode()); //proxyBeanMethods = true 是单例

        Dog bean1 = ioc.getBean(Dog.class);
        Cat bean2 = ioc.getBean(Cat.class);
        System.out.println(bean1);
        System.out.println(bean2);


        //访问静态资源，图片等要放在下面这些路径下
        //"classpath:/META-INF/resources/",
        // "classpath:/resources/",
        // "classpath:/static/",
        // "classpath:/public/"

        //如果要为访问图片等资源增加前缀来避免与页面路径名重复
        //可以在application.yml或application.properties下设置
        // spring.mvc.static-path-pattern=/** -> spring.mvc.static-path-pattern=/xx/**
    }
}
